package com.zsrt.devbase.common.utils;

import java.io.IOException;
import java.util.Iterator;
import java.util.Map;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.URI;
import org.apache.commons.httpclient.methods.GetMethod;

/**
 * Created by yzj on 2017/4/6.
 */
public class HttpUtil {

    private static HttpUtil httpUtil = new HttpUtil();

    private HttpUtil() {

    }

    public static HttpUtil getInstance() {
        return httpUtil;
    }

    @SuppressWarnings({"deprecation", "unused"})
	public String getHtmlReponse(String url,Map<String,String> params) throws IOException {
        HttpClient httpClient = new HttpClient();
        GetMethod get = new GetMethod();
        String urlPath = url;
        urlPath+="?";
        Iterator<Map.Entry<String, String>> iterator= params.entrySet().iterator();
        while (iterator.hasNext()){
            Map.Entry<String, String> entry= iterator.next();
            urlPath+=entry.getKey()+"&"+entry.getValue();
            if(iterator.hasNext()){
                urlPath+="&";
            }
        }
        get.setURI(new URI(url));

        httpClient.executeMethod(get);
        String response = get.getResponseBodyAsString();
        return response;
    }


}
